﻿using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http.Filters;

namespace EnvirProtection.App_Start
{
    public class WebApiExceptionFilter:ExceptionFilterAttribute
    {
        private static ILog log = LogManager.GetLogger(typeof(WebApiExceptionFilter));
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            var logMessage =
                $"controller.action={actionExecutedContext.ActionContext.ControllerContext.ControllerDescriptor.ControllerName}.{actionExecutedContext.ActionContext.ActionDescriptor.ActionName}:exception="
                + actionExecutedContext.Exception.Message;//异常内容
            log.Error(logMessage);
        }
    }
}